import grpc
from concurrent import futures
import prime_pb2
import prime_pb2_grpc

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

class PrimeService(prime_pb2_grpc.PrimeServiceServicer):
    def CalculatePrimes(self, request, context):
        primes = [n for n in range(request.start, request.end + 1) if is_prime(n)]
        return prime_pb2.PrimeReply(primes=primes)

def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    prime_pb2_grpc.add_PrimeServiceServicer_to_server(PrimeService(), server)
    server.add_insecure_port('[::]:50051')
    server.start()
    server.wait_for_termination()

if __name__ == '__main__':
    serve()